<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Article extends Model
{
    public $dateFormat = 'U';
    public $table = 'articles';

    //关联表

    /**
     * 关联user 一对一
     */
    public function user()
    {
        return $this->hasOne(User::class,'id','user_id')->select('id','username','avatar');
    }

    /**
     * 关联cates 一对一
     */
    public function cates()
    {
        return $this->hasOne(Cates::class,'id','cates_id')->select('id','name','icon');
    }

    /**
     * 关联tabs 一对一
     */
    public function tabs()
    {
        return $this->hasOne(Tab::class,'id','tab')->select('id','name');
    }

    /**
     * 评论表
     */
    public function comment()
    {
        return $this->hasMany('App\Model\Comment','article_id','id');
    }
}
